<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile
use Magento\Framework\Json\Helper\Data;

/** @var \Magento\Payment\Block\Transparent\Iframe $block */
$params = $block->getParams();
?>
<html>
    <head>
        <script>
        <?php if (isset($params['redirect'])): ?>
            window.location="<?php echo $block->escapeUrl($params['redirect']); ?>";
        <?php elseif (isset($params['redirect_parent'])): ?>
            var require = window.top.require;
            require(
                [
                    'jquery'
                ],
                function($) {
                    var parent = window.top;
                    $(parent).trigger('clearTimeout');
                    parent.location="<?php echo $block->escapeUrl($params['redirect_parent']); ?>";
                }
            );
        <?php elseif (isset($params['error_msg'])): ?>
            var require = window.top.require;
            require(
                [
                    'jquery',
                    'Magento_Ui/js/model/messageList',
                    'mage/translate'
                ],
                function($, globalMessageList, $t) {
                    var parent = window.top;
                    $(parent).trigger('clearTimeout');
                    globalMessageList.addErrorMessage({
                        message: $t('An error occurred on the server. Please try to place the order again.')
                    });
                }
            );
        <?php elseif (isset($params['order_success'])): ?>
            window.top.location = "<?php echo $block->escapeUrl($params['order_success']); ?>";
        <?php else: ?>
            var require = window.top.require;
            require(
                [
                    'jquery',
                    'Magento_Checkout/js/model/quote',
                    'Magento_Checkout/js/action/place-order',
                    'Magento_Checkout/js/action/redirect-on-success'
                ],
                function($, quote, placeOrderAction, redirectOnSuccessAction) {
                    var parent = window.top;

                    $(parent).trigger('clearTimeout');
                    $.when(
                        placeOrderAction({'method': quote.paymentMethod().method})
                    ).done(
                        function () {
                            redirectOnSuccessAction.execute();
                        }
                    );
                }
            );
        <?php endif; ?>
        </script>
    </head>
    <body></body>
</html>
